package com.lq.educationsystem.examination.controller;

import com.lq.educationsystem.common.entiy.ClassesSubjectTb;
import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.vo.ExaminationPageVo;
import com.lq.educationsystem.common.vo.TeacherSubjectExaminationVo;
import com.lq.educationsystem.examination.entiy.ExaminationTb;
import com.lq.educationsystem.examination.service.ExaminationBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "考试信息")
@RequestMapping("/examination/base")
@RestController
public class ExaminationBaseController {

    //注入service
    @Autowired
    ExaminationBaseService examinationBaseService;
    //增加
    @Operation(summary = "插入考试信息")
    @PostMapping("/insert")
    public Result insertInfo(@RequestBody ExaminationTb examinationInfo){
        examinationBaseService.insertInfo(examinationInfo);

        return ResultBuild.buildOk();
    }
    //删除
    @Operation(summary = "通过考试id删除考试信息")
    @PostMapping("/delete")
    public Result deleteById(@RequestBody ExaminationTb examinationInfo){
        Integer examinationId = examinationInfo.getExaminationId();
        //删除
        examinationBaseService.deleteById(examinationId);
        return ResultBuild.buildOk();

    }
    //更新
    @Operation(summary = "更新考试信息")
    @PostMapping("/update")
    public Result updateInfo(@RequestBody ExaminationTb examinationInfo){
        examinationBaseService.updateInfo(examinationInfo);

        return ResultBuild.buildOk();
    }
    //通过id查询
    @Operation(summary = "通过考试id查询考试信息")
    @PostMapping("/querybyid")
    public Result<ExaminationTb> queryById(@RequestBody ExaminationTb examinationInfo){
        Integer examinationId = examinationInfo.getExaminationId();
        //通过id查询
        Result result= examinationBaseService.queryById(examinationId);

        return result;
    }
    //查询api
    @Operation(summary = "分页查询考试信息")
    @PostMapping("/query")
    public ResultPage<ExaminationTb> queryList(@RequestBody ExaminationPageVo examinationPageVo){
        ResultPage<ExaminationTb> examinationTbResultPage = examinationBaseService.queryList(examinationPageVo);

        return examinationTbResultPage;

    }
    /**
     * 根据课程id查询数据
     */
    @Operation(summary = "通过课程id查询考试信息")
    @PostMapping("/query/examination")
    public ResultPage<ExaminationTb> queryExaminationInfoBySubjectId(@RequestBody List<Integer> collectSubjectIdInfoList){
        ResultPage<ExaminationTb> examinationTbResultPage = examinationBaseService.queryExaminationInfoBySubjectId(collectSubjectIdInfoList);

        return examinationTbResultPage;
    }

    /**
     * 根据考试信息和课程id 添加并且获取考试信息
     */

    @Operation(summary = "通过考试id和课程信息添加并且获取考试信息")
    @PostMapping("/add/examiantion/info")
    public Result<ExaminationTb> addExaminationInfoByExaminationInfoAndSubjectId(@RequestBody TeacherSubjectExaminationVo teacherSubjectExaminationVo) {
        Result<ExaminationTb> examinationTbResultPage = examinationBaseService.addExaminationInfoByExaminationInfoAndSubjectId(teacherSubjectExaminationVo);
        return examinationTbResultPage;
    }
}
